//
//  VideoViewController.m
//  LiveSoftware
//
//  Created by lanou3g on 15/7/10.
//  Copyright (c) 2015年 lanou3g. All rights reserved.
//

#import "VideoViewController.h"

#define kTitleY kScreenIp6(20)
#define kBtnWidth kScreenIp6(60)
#define kBtnHeight kScreenIp6(40)

#pragma mark -----
/**
 * url 后拼接 currentTime
 */
#define kZuqiuTuijianUrl @"http://zhiboba.3b2o.com/videoIndex/ListJson/category/soccer?"
#define kLanqiuTuijianUrl @"http://zhiboba.3b2o.com/videoIndex/ListJson/category/basketball?"

#define kZuqiuJijinUrl @"http://zhiboba.3b2o.com/recording/relatedVideoListJson/category/soccer?"
#define kLanqiuJijinUrl @"http://zhiboba.3b2o.com/recording/relatedVideoListJson/category/basketball?"

/**
 * 上拉加载更多 (推荐1、2 拼接 modtime_src, 2 后拼接currentTime)
 */
#define kTuijianMoreUrlPart1 @"http://zhiboba.3b2o.com/videoIndex/ListJson/modtime/"
#define kJijinMoreUrlPart1 @"http://zhiboba.3b2o.com/recording/relatedVideoListJson/date/"

#define kZuqiuMoreUrl @"/category/soccer?"
#define kLanqiuMoreUrl @"/category/basketball?"





@interface VideoViewController () <UITableViewDelegate,UITableViewDataSource,UIScrollViewDelegate>

@property(nonatomic,strong) VideoView *videoView;

// 时间数组
@property(nonatomic,strong) NSArray *dateArray;
// 足球时间数组
@property(nonatomic,strong) NSMutableArray *zuqiuDateArray;
// 篮球时间数组
@property(nonatomic,strong) NSMutableArray *lanqiuDateArray;

// 推荐数组
@property(nonatomic,strong) NSArray *recommendArray;
// 足球推荐
@property(nonatomic,strong) NSMutableArray *zuqiuRecomArray;
// 篮球推荐
@property(nonatomic,strong) NSMutableArray *lanqiuRecomArray;

// 集锦数组
@property(nonatomic,strong) NSMutableArray *jijinArray;
// 足球集锦
@property(nonatomic,strong) NSMutableArray *zuqiuJijinArray;
// 篮球集锦
@property(nonatomic,strong) NSMutableArray *lanqiuJijinArray;

// 录像数组
@property(nonatomic,strong) NSMutableArray *videoArray;
// 足球录像
@property(nonatomic,strong) NSMutableArray *zuqiuVideoArray;
// 篮球录像
@property(nonatomic,strong) NSMutableArray *lanqiuVideoArray;

// 判定篮球是否被选中
@property(nonatomic,getter=isSelected) BOOL selected;


// 现在的时间 (拼接数据用)
@property(nonatomic,copy)NSString *currentTime;


@end

@implementation VideoViewController

#pragma mark ----------------------------------------------------------

// 得到10位的 秒 的当前时间
- (NSString*)getCurentTime_10
{
    
    NSDate *today = [NSDate date];
    
    double dureen = [today timeIntervalSince1970];
    
    NSString *timeString = [NSString stringWithFormat:@"%f",dureen];
    
    NSString* miao = [[timeString componentsSeparatedByString:@"."]objectAtIndex:0];
    
    
    return miao;
    
}


#pragma mark 解析数据

- (void)loadData
{
    
    // 当前时间 (拼接用)
    self.currentTime = [self getCurentTime_10];
    
#pragma mark 加载足球 推荐 数据
    
    // 当前足球推荐的 url
    NSString *zuqiuTuijianUrl = [NSString stringWithFormat:@"%@%@",kZuqiuTuijianUrl,_currentTime];
//    NSLog(@"%@",zuqiuTuijianUrl);
    
    [LORequestManger GET:zuqiuTuijianUrl success:^(id response) {
        
        self.zuqiuRecomArray = [NSMutableArray array];
        NSDictionary *sDic = (NSDictionary *)response;
        NSArray *videos = sDic[@"videos"];
        
        for (NSDictionary *dic in videos)
        {
            RecommendModel *model = [RecommendModel modelWithDictionary:dic];
            [self.zuqiuRecomArray addObject:model];
        }
        
        
        [self switchArrayData];
        
        
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        NSLog(@"%@",error);
    }];
    
#pragma mark 加载篮球 推荐 数据
    
    [self loadLanqiuTuijianData];

    
#pragma mark 集锦 录像
    
    // 得到当前足球 集锦和录像 的 url
    NSString *zuqiuJijinUrl = [NSString stringWithFormat:@"%@%@",kZuqiuJijinUrl,_currentTime];
//    NSLog(@"%@",zuqiuJijinUrl);
    
    [LORequestManger GET:zuqiuJijinUrl success:^(id response) {
        
        self.zuqiuDateArray = [NSMutableArray array];
        self.zuqiuJijinArray = [NSMutableArray array];
        self.zuqiuVideoArray = [NSMutableArray array];
        
        NSDictionary *superDic = (NSDictionary *)response;
        NSArray *relatedVideos = superDic[@"relatedVideos"];
        
        for (NSDictionary *subDic in relatedVideos)
        {
            [self.zuqiuDateArray addObject:subDic[@"date"]];
            self.dateArray = self.zuqiuDateArray;
            
            NSArray *games = subDic[@"games"];
            NSMutableArray *jijinModelArray = [NSMutableArray array];
            NSMutableArray *videoModelArray = [NSMutableArray array];
            for (NSDictionary *dic in games)
            {
                
                JijinVideoModel *model = [JijinVideoModel modelWithDictionary:dic];
                
                if (model.hasHighlights)
                {
                    [jijinModelArray addObject:model];
                }
                if (model.hasRecording)
                {
                    [videoModelArray addObject:model];
                }
                
            }
            [self.zuqiuJijinArray addObject:jijinModelArray];
            [self.zuqiuVideoArray addObject:videoModelArray];
        }
        
        [self switchArrayData];
        
        
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        NSLog(@"%@",error);
    }];
    
#pragma mark 加载篮球 集锦录像 数据
    
    [self loadLanqiuJijinData];
    
}

// 加载篮球 推荐 数据
- (void)loadLanqiuTuijianData
{
    // 当前篮球推荐的 url
    NSString *lanqiuTuijianUrl = [NSString stringWithFormat:@"%@%@",kLanqiuTuijianUrl,_currentTime];
    
    [LORequestManger GET:lanqiuTuijianUrl success:^(id response) {
        
        self.lanqiuRecomArray = [NSMutableArray array];
        NSDictionary *sDic = (NSDictionary *)response;
        NSArray *videos = sDic[@"videos"];
        
        for (NSDictionary *dic in videos)
        {
            RecommendModel *model = [RecommendModel modelWithDictionary:dic];
            // 得到篮球数据
            [self.lanqiuRecomArray addObject:model];
        }
        
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        NSLog(@"%@",error);
    }];
    
}

// 加载篮球 集锦录像 数据
- (void)loadLanqiuJijinData
{
    
    // 得到当前篮球 集锦和录像 的 url
    NSString *lanqiuJijinUrl = [NSString stringWithFormat:@"%@%@",kLanqiuJijinUrl,_currentTime];
    
    [LORequestManger GET:lanqiuJijinUrl success:^(id response) {
        
        self.lanqiuDateArray = [NSMutableArray array];
        self.lanqiuJijinArray = [NSMutableArray array];
        self.lanqiuVideoArray = [NSMutableArray array];
        
        NSDictionary *superDic = (NSDictionary *)response;
        NSArray *relatedVideos = superDic[@"relatedVideos"];
        
        for (NSDictionary *subDic in relatedVideos)
        {
            [self.lanqiuDateArray addObject:subDic[@"date"]];
            
            NSArray *games = subDic[@"games"];
            NSMutableArray *jijinModelArray = [NSMutableArray array];
            NSMutableArray *videoModelArray = [NSMutableArray array];
            for (NSDictionary *dic in games)
            {
                
                JijinVideoModel *model = [JijinVideoModel modelWithDictionary:dic];
                
                if (model.hasHighlights)
                {
                    [jijinModelArray addObject:model];
                }
                if (model.hasRecording)
                {
                    [videoModelArray addObject:model];
                }
                
            }
            // 得到篮球 集锦和录像 数据
            [self.lanqiuJijinArray addObject:jijinModelArray];
            [self.lanqiuVideoArray addObject:videoModelArray];
        }
        
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        NSLog(@"%@",error);
    }];
    
}


#pragma mark 切换 足球/篮球 数据
- (void)switchArrayData
{
    
    if (self.isSelected)
    {
        self.recommendArray = self.lanqiuRecomArray;
        self.dateArray = self.lanqiuDateArray;
        self.jijinArray = self.lanqiuJijinArray;
        self.videoArray = self.lanqiuVideoArray;
    }
    else
    {
        self.recommendArray = self.zuqiuRecomArray;
        self.dateArray = self.zuqiuDateArray;
        self.jijinArray = self.zuqiuJijinArray;
        self.videoArray = self.zuqiuVideoArray;
    }
    
    [self.videoView.leftTableView reloadData];
    [self.videoView.centerTableView reloadData];
    [self.videoView.rightTableView reloadData];
    
}

#pragma mark - =============================================================================

- (void)viewDidLoad {
    
    [super viewDidLoad];
    
    [self loadData];
    
    self.videoView = [[VideoView alloc] initWithFrame:[UIScreen mainScreen].bounds];
    [self.view addSubview:_videoView];
    
    
    self.videoView.baseScrollView.delegate = self;
    self.videoView.leftTableView.delegate = self;
    self.videoView.leftTableView.dataSource = self;
    self.videoView.centerTableView.delegate = self;
    self.videoView.centerTableView.dataSource = self;
    self.videoView.rightTableView.delegate = self;
    self.videoView.rightTableView.dataSource = self;
    
    
    self.videoView.leftTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    self.videoView.centerTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    self.videoView.rightTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    
    
    [self.videoView.leftButton addTarget:self action:@selector(leftButtonAction) forControlEvents:UIControlEventTouchUpInside];
    [self.videoView.rightButton addTarget:self action:@selector(rightButtonAction) forControlEvents:UIControlEventTouchUpInside];
    [self.videoView.nextButton addTarget:self action:@selector(nextButtonAction) forControlEvents:UIControlEventTouchUpInside];
    
    [self.videoView.recommendBtn addTarget:self action:@selector(recommendBtnAction) forControlEvents:UIControlEventTouchUpInside];
    [self.videoView.collectionBtn addTarget:self action:@selector(collectionBtnAction) forControlEvents:UIControlEventTouchUpInside];
    [self.videoView.videoBtn addTarget:self action:@selector(videoBtnAction) forControlEvents:UIControlEventTouchUpInside];
    

    // 下拉刷新
    [self headerRefreshing];
    // 上拉加载更多
    [self footerRefreshing];
}



#pragma mark -------------------------------------------- UITableView 数据源方法

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    if (tableView == self.videoView.leftTableView)
    {
        return 1;
    }
    else if (tableView == self.videoView.centerTableView)
    {
        return self.jijinArray.count;
    }
    else
    {
        return self.videoArray.count;
    }
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (tableView == self.videoView.leftTableView)
    {
        return self.recommendArray.count;
    }
    else if (tableView == self.videoView.centerTableView)
    {
        NSArray *array = self.jijinArray[section];
        return array.count;
    }
    else
    {
        NSArray *array  = self.videoArray[section];
        return array.count;
    }
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (tableView == self.videoView.leftTableView)
    {
        static NSString *recommendCell = @"recommendCell";
        [tableView registerClass:[RecommendTableViewCell class] forCellReuseIdentifier:recommendCell];
        RecommendTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:recommendCell forIndexPath:indexPath];
        
        RecommendModel *model = self.recommendArray[indexPath.row];
        [cell setModelWith:model];
        
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        return cell;
    }
    else
    {
        
        if (tableView == self.videoView.centerTableView)
        {
            static NSString *jijinCell = @"jijinCell";
            [tableView registerClass:[VideoTableViewCell class] forCellReuseIdentifier:jijinCell];
            VideoTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:jijinCell forIndexPath:indexPath];
            
            NSArray *modelArray = self.jijinArray[indexPath.section];
            [cell setModelWith:modelArray[indexPath.row]];
            
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
            return cell;
        }
        else
        {
            static NSString *videoCell = @"videoCell";
            [tableView registerClass:[VideoTableViewCell class] forCellReuseIdentifier:videoCell];
            VideoTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:videoCell forIndexPath:indexPath];
            
            NSArray *modelArray = self.videoArray[indexPath.section];
            [cell setModelWith:modelArray[indexPath.row]];
            
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
            return cell;
        }
        
    }

}


#pragma mark ----------------------------------------------- UITableView 代理方法

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (tableView == self.videoView.leftTableView)
    {
        return kScreenIp6(100);
    }
    else if (tableView == self.videoView.centerTableView)
    {
        return kScreenIp6(90);
    }
    else
    {
        return kScreenIp6(90);
    }
    
}


#pragma mark - 自定义分区头视图
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    
    if (tableView == self.videoView.leftTableView)
    {
        return nil;
    }
    else
    {
        SectionHeaderView *headerView = [[SectionHeaderView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, kScreenIp6(30))];
        headerView.headerLabel.text = self.dateArray[section];
        
        return headerView;
    }
    
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    if (tableView == self.videoView.leftTableView)
    {
        return 0;
    }
    else
    {
        return kScreenIp6(30);
    }
}


#pragma mark - 点击 cell 触发事件
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    if (self.videoView.rightButton.hidden)
    {
        if (tableView == self.videoView.leftTableView)
        {
            PlayViewController *playVc = [[PlayViewController alloc] init];
            
            RecommendModel *model = self.recommendArray[indexPath.row];
            playVc.playUrl = model.defaultMobileLink;
//            NSLog(@"%@",model.modtime_src);
            [self.navigationController pushViewController:playVc animated:YES];
            
        }
        else if (tableView == self.videoView.centerTableView)
        {
            JijinDetailController *jijinDetVc = [[JijinDetailController alloc] init];
            
            NSArray *modelArray = self.jijinArray[indexPath.section];
            JijinVideoModel *model = modelArray[indexPath.row];
            
            jijinDetVc.sid = model.sid;
            jijinDetVc.hostInfo = model.hostInfo;
            jijinDetVc.guestInfo = model.guestInfo;
            
            [self.navigationController pushViewController:jijinDetVc animated:YES];
        }
        else
        {
            VideoDetailController *videoDetVc = [[VideoDetailController alloc] init];
            
            NSArray *modelArray = self.videoArray[indexPath.section];
            JijinVideoModel *model = modelArray[indexPath.row];
            
            videoDetVc.sid = model.sid;
            videoDetVc.hostInfo = model.hostInfo;
            videoDetVc.guestInfo = model.guestInfo;
            
            [self.navigationController pushViewController:videoDetVc animated:YES];
        }
        
    }
    else
    {
        [self leftButtonAction];
    }
    
}




#pragma mark - --------------------------------------------------- 下拉刷新

- (void)headerRefreshing
{
    __unsafe_unretained typeof(self) vc = self;
    [self.videoView.leftTableView addLegendHeaderWithRefreshingBlock:^{
        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
            
            // 重新加载 刷新表格
            [vc loadData];
            // (最好在刷新表格后调用)调用endRefreshing可以结束刷新状态
            [vc.videoView.leftTableView.header endRefreshing];
            
        });
    }];
    
    [self.videoView.centerTableView addLegendHeaderWithRefreshingBlock:^{
        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
            // 重新加载 刷新表格
            [vc loadData];
            // (最好在刷新表格后调用)调用endRefreshing可以结束刷新状态
            [vc.videoView.centerTableView.header endRefreshing];
        });
    }];
    
    [self.videoView.rightTableView addLegendHeaderWithRefreshingBlock:^{
        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
            // 重新加载 刷新表格
            [vc loadData];
            // (最好在刷新表格后调用)调用endRefreshing可以结束刷新状态
            [vc.videoView.rightTableView.header endRefreshing];
        });
    }];
}

#pragma mark - --------------------------------------------------- 上拉加载更多

- (void)footerRefreshing
{
    __unsafe_unretained typeof(self) vc = self;
    
    
    [self.videoView.leftTableView addLegendFooterWithRefreshingBlock:^{
        
        // 1.添加数据
        [vc loadMoreTuijianData];
        
        // 2.2秒后刷新表格UI
        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
            
            // 刷新表格
            [vc.videoView.leftTableView reloadData];
            
            // (最好在刷新表格后调用)调用endRefreshing可以结束刷新状态
            [vc.videoView.leftTableView.footer endRefreshing];
        });
    }];
    
    [self.videoView.centerTableView addLegendFooterWithRefreshingBlock:^{
        
        // 1.添加数据
        [vc loadMoreJijinData];
        
        // 2.2秒后刷新表格UI
        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
            
            // 刷新表格
            [vc.videoView.centerTableView reloadData];
            
            // (最好在刷新表格后调用)调用endRefreshing可以结束刷新状态
            [vc.videoView.centerTableView.footer endRefreshing];
        });
    }];
    
    [self.videoView.rightTableView addLegendFooterWithRefreshingBlock:^{
        
        // 1.添加数据
        [vc loadMoreJijinData];
        
        // 2.2秒后刷新表格UI
        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
            
            // 刷新表格
            [vc.videoView.rightTableView reloadData];
            
            // (最好在刷新表格后调用)调用endRefreshing可以结束刷新状态
            [vc.videoView.rightTableView.footer endRefreshing];
        });
    }];
    
    
}

// 加载更多 推荐数据
- (void)loadMoreTuijianData
{
    RecommendModel *model = [self.recommendArray lastObject];
    NSString *modtime_src = model.modtime_src;
    NSString *currentTime = [self getCurentTime_10];
    
    if (!self.isSelected) {
        // 足球
        NSString *moreUrl = [NSString stringWithFormat:@"%@%@%@%@",kTuijianMoreUrlPart1,modtime_src,kZuqiuMoreUrl,currentTime];
        
        [LORequestManger GET:moreUrl success:^(id response) {
            
            NSDictionary *sDic = (NSDictionary *)response;
            NSArray *videos = sDic[@"videos"];
            
            for (NSDictionary *dic in videos)
            {
                RecommendModel *model = [RecommendModel modelWithDictionary:dic];
                [self.zuqiuRecomArray addObject:model];
            }
            
            self.recommendArray = self.zuqiuRecomArray;
            
        } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
            NSLog(@"%@",error);
        }];
    }
    else
    {
        // 篮球
        NSString *moreUrl = [NSString stringWithFormat:@"%@%@%@%@",kTuijianMoreUrlPart1,modtime_src,kLanqiuMoreUrl,currentTime];
        
        [LORequestManger GET:moreUrl success:^(id response) {
            
            NSDictionary *sDic = (NSDictionary *)response;
            NSArray *videos = sDic[@"videos"];
            
            for (NSDictionary *dic in videos)
            {
                RecommendModel *model = [RecommendModel modelWithDictionary:dic];
                [self.lanqiuRecomArray addObject:model];
            }
            
            self.recommendArray = self.lanqiuRecomArray;
            
        } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
            NSLog(@"%@",error);
        }];
    }
    
}

// 加载更多 集锦/录像 数据
- (void)loadMoreJijinData
{
    
    JijinVideoModel *model = [[self.jijinArray lastObject] lastObject];
    NSString *data = model.ymd;
    NSString *currentTime = [self getCurentTime_10];
    
    if (!self.isSelected)
    {
        // 足球
        NSString *jijinUrl = [NSString stringWithFormat:@"%@%@%@%@",kJijinMoreUrlPart1,data,kZuqiuMoreUrl,currentTime];
        
        [LORequestManger GET:jijinUrl success:^(id response) {
            
            
            NSDictionary *superDic = (NSDictionary *)response;
            NSArray *relatedVideos = superDic[@"relatedVideos"];
            
            for (NSDictionary *subDic in relatedVideos)
            {
                [self.zuqiuDateArray addObject:subDic[@"date"]];
                self.dateArray = self.zuqiuDateArray;
                
                NSArray *games = subDic[@"games"];
                NSMutableArray *jijinModelArray = [NSMutableArray array];
                NSMutableArray *videoModelArray = [NSMutableArray array];
                for (NSDictionary *dic in games)
                {
                    
                    JijinVideoModel *model = [JijinVideoModel modelWithDictionary:dic];
                    
                    if (model.hasHighlights)
                    {
                        [jijinModelArray addObject:model];
                    }
                    if (model.hasRecording)
                    {
                        [videoModelArray addObject:model];
                    }
                    
                }
                [self.zuqiuJijinArray addObject:jijinModelArray];
                [self.zuqiuVideoArray addObject:videoModelArray];
            }
            
            [self switchArrayData];
            
            
        } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
            NSLog(@"%@",error);
        }];
    }
    else
    {
        // 篮球
        NSString *jijinUrl = [NSString stringWithFormat:@"%@%@%@%@",kJijinMoreUrlPart1,data,kLanqiuMoreUrl,currentTime];
        
        [LORequestManger GET:jijinUrl success:^(id response) {
            
            
            NSDictionary *superDic = (NSDictionary *)response;
            NSArray *relatedVideos = superDic[@"relatedVideos"];
            
            for (NSDictionary *subDic in relatedVideos)
            {
                [self.lanqiuDateArray addObject:subDic[@"date"]];
                self.dateArray = self.lanqiuDateArray;
                
                NSArray *games = subDic[@"games"];
                NSMutableArray *jijinModelArray = [NSMutableArray array];
                NSMutableArray *videoModelArray = [NSMutableArray array];
                for (NSDictionary *dic in games)
                {
                    
                    JijinVideoModel *model = [JijinVideoModel modelWithDictionary:dic];
                    
                    if (model.hasHighlights)
                    {
                        [jijinModelArray addObject:model];
                    }
                    if (model.hasRecording)
                    {
                        [videoModelArray addObject:model];
                    }
                    
                }
                [self.lanqiuJijinArray addObject:jijinModelArray];
                [self.lanqiuVideoArray addObject:videoModelArray];
            }
            
            [self switchArrayData];
            
            
        } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
            NSLog(@"%@",error);
        }];
    }
    
    
}




#pragma mark - ------------------------------------------------------ 点击事件

#pragma mark 推荐模块
- (void)recommendBtnAction
{
    if (self.videoView.rightButton.hidden)
    {
        [UIView beginAnimations:nil context:nil];
        [UIView setAnimationDuration:0.5];
        [UIView setAnimationDelegate:self];
        
        
        self.videoView.baseScrollView.contentOffset = CGPointMake(0, 0);
        [self switchButtonPoint];

        
        [UIView commitAnimations];
    }
    else
    {
        [self leftButtonAction];
    }
}

#pragma mark 集锦模块
- (void)collectionBtnAction
{
    if (self.videoView.rightButton.hidden) {
        [UIView beginAnimations:nil context:nil];
        [UIView setAnimationDuration:0.5];
        [UIView setAnimationDelegate:self];
        
        
        self.videoView.baseScrollView.contentOffset = CGPointMake(kScreenWidth, 0);
        [self switchButtonPoint];
        
        
        [UIView commitAnimations];
    }
    else
    {
        [self leftButtonAction];
    }
}

#pragma mark 录像模块
- (void)videoBtnAction
{
    if (self.videoView.rightButton.hidden) {
        [UIView beginAnimations:nil context:nil];
        [UIView setAnimationDuration:0.5];
        [UIView setAnimationDelegate:self];
        
        
        self.videoView.baseScrollView.contentOffset = CGPointMake(kScreenWidth*2, 0);
        [self switchButtonPoint];

        
        [UIView commitAnimations];
    }
    else
    {
        [self leftButtonAction];
    }
}


#pragma mark - ---------------------------------------------------ScrollView 代理方法

#pragma mark 拖动中执行
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:0.5];
    [UIView setAnimationDelegate:self];
    
    int i = (self.videoView.baseScrollView.contentOffset.x + kScreenWidth/2) / kScreenWidth;
    self.videoView.pointImage.center = CGPointMake((i * kScreenWidth/3 + kScreenWidth/6), kScreenIp6(106));
    
    [UIView commitAnimations];
}

#pragma mark 拖拽后减速停止触发
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:0.3];
    [UIView setAnimationDelegate:self];
    
    [self switchButtonPoint];
    
    [UIView commitAnimations];
}

// 切换 Button 指向
- (void)switchButtonPoint
{
    if (self.videoView.baseScrollView.contentOffset.x == 0)
    {
        self.videoView.pointImage.center = CGPointMake(kScreenWidth/6, kScreenIp6(106));
        [self.videoView.recommendBtn setTintColor:[UIColor whiteColor]];
        [self.videoView.collectionBtn setTintColor:[UIColor colorWithWhite:0.900 alpha:1.000]];
        [self.videoView.videoBtn setTintColor:[UIColor colorWithWhite:0.900 alpha:1.000]];
    }
    else if (self.videoView.baseScrollView.contentOffset.x == kScreenWidth)
    {
        self.videoView.pointImage.center = CGPointMake(kScreenWidth/2, kScreenIp6(106));
        [self.videoView.collectionBtn setTintColor:[UIColor whiteColor]];
        [self.videoView.recommendBtn setTintColor:[UIColor colorWithWhite:0.900 alpha:1.000]];
        [self.videoView.videoBtn setTintColor:[UIColor colorWithWhite:0.900 alpha:1.000]];
    }
    else
    {
        self.videoView.pointImage.center = CGPointMake(kScreenWidth*5/6, kScreenIp6(106));
        [self.videoView.videoBtn setTintColor:[UIColor whiteColor]];
        [self.videoView.collectionBtn setTintColor:[UIColor colorWithWhite:0.900 alpha:1.000]];
        [self.videoView.recommendBtn setTintColor:[UIColor colorWithWhite:0.900 alpha:1.000]];
    }
}

#pragma mark - --------------------------------------------------- 足球篮球Button

- (void)leftButtonAction
{
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:0.5];
    [UIView setAnimationDelegate:self];
    
    if (self.videoView.rightButton.hidden)
    {
        self.videoView.rightButton.hidden = NO;
        self.videoView.nextButton.hidden = YES;
        self.videoView.leftButton.frame = CGRectMake(kScreenWidth / 2 - kBtnWidth - kScreenIp6(10), kTitleY, kBtnWidth, kBtnHeight);
    }
    else
    {
        self.videoView.rightButton.hidden = YES;
        self.videoView.nextButton.hidden = NO;
        self.videoView.leftButton.frame = CGRectMake((kScreenWidth - kBtnWidth- kScreenIp6(10)) / 2, kTitleY, kBtnWidth, kBtnHeight);
    }
    
    [UIView commitAnimations];
}


- (void)rightButtonAction
{
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:0.5];
    [UIView setAnimationDelegate:self];
    
    self.videoView.rightButton.hidden = YES;
    self.videoView.nextButton.hidden = NO;
    NSString *string = self.videoView.leftButton.titleLabel.text;
    [self.videoView.leftButton setTitle:self.videoView.rightButton.titleLabel.text forState:UIControlStateNormal];
    [self.videoView.rightButton setTitle:string forState:UIControlStateNormal];
    self.videoView.leftButton.frame = CGRectMake((kScreenWidth - kBtnWidth- kScreenIp6(10)) / 2, kTitleY, kBtnWidth, kBtnHeight);
    
    
    // 改变 足球/篮球 选择状态
    self.selected = !self.isSelected;
    
    // 切换数据 并刷新数据
    [self switchArrayData];

    
    [UIView commitAnimations];
}


- (void)nextButtonAction
{
    [self leftButtonAction];
}


#pragma mark - 点击屏幕默认
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    if (!self.videoView.rightButton.hidden) {
        [self leftButtonAction];
    }
}

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
    
}

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
    
}


#pragma mark - 视图即将出现
- (void)viewWillAppear:(BOOL)animated
{
    [self.navigationController setNavigationBarHidden:YES];

}
#pragma mark - 视图即将消失
- (void)viewWillDisappear:(BOOL)animated
{
    [self.navigationController setNavigationBarHidden:NO];
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}


@end
